<?php
/*
	销售员中心
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
set_html('title','销售中心');
if($_RQ['op']=='main'){
	$return['setting']=$this->plugin_setting('page');
	set_html('title',$return['setting']['center']);
	$member=$this->get('member',array('mid'=>$_SESSION['uid']));
	$basic=model('core/member')->basic($_SESSION['uid']);
	$member=array_merge($member,$basic);
	$return['member']=$member;
	if($member['fromuser']){
		$return['shangji']=model('core/member')->basic($member['fromuser']);
	}
	$return['team']=$this->get('team',array('mid'=>$_SESSION['uid']));
	$return['team']['levelname']=$this->getcolumn('level',array('id'=>$return['team']['level_id']),'title');
	$return['team']['levelname']=$return['team']['levelname']?:'销售员';
	$data=array();
	//已结算佣金
	$data['balance_total']=$this->sum('balance',array('mid'=>$_SESSION['uid']),'money');
	$data['balance_num']=$this->count('balance',array('mid'=>$_SESSION['uid']));
	//待结算佣金
	$params=array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid'],'status'=>1);
	/*if($this->setting['balance_day']){
		//结算天数
		$time=TIMESTAMP-intval($this->setting['balance_day'])*86400;
		$params['complete_time <']=$time;
	}*/
	$data['commission_1']=$this->sum('commission',$params,'money');
	$data['commission_total']=$this->sum('commission',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid']),'money');
	$data['feenum']=$this->count('commission',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid']),'id');
	$data['area_num']=$this->count('member',array('uniacid'=>$_SESSION['uniacid'],'fromuser'=>$_SESSION['uid']));
	$params=array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid']);
	$params['type']=array(0);
	$data['sale_money']=$this->sum('commission',$params,'money');
	$params['type']=1;
	$data['guan_money']=$this->sum('commission',$params,'money');
	$params['type']=2;
	$data['fuwu_money']=$this->sum('commission',$params,'money');
	$params['type']=3;
	$data['ping_money']=$this->sum('commission',$params,'money');
	$return['team']['order_num']=$this->count('commission',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid']));
	$params=array('uniacid'=>$_SESSION['uniacid']);
	$orderby='level asc';
	$alllevels=$this->getall('level',$params,array(),'',$orderby);
	$levelnum=count($alllevels)+2;
	$agent_ids=$_SESSION['uid'];
	$agent_num=0;
	for($i=0;$i<$levelnum;$i++){
		$level=$i+1;
		if(!$agent_ids){
			$levels[$level]=0;
			break;
		}
		$agent_ids=$this->getall('member',array('fromuser'=>$agent_ids),array('mid'),'mid');
		
		if(!$agent_ids){
			$levels[$level]=0;
		}else{
			$agent_ids=array_keys($agent_ids);
			$levels[$level]=count($agent_ids);
			$agent_num +=$levels[$level];
		}
	}
	$data['agent_num']=$agent_num;
	$return['data']=$data;
	exi($return);
}

?>